package net.yla.smartbus.core.api;

import net.yla.smartbus.core.exception.AppException;

/**
 * web层响应返回封装
 *
 * @author ZengXiaoLiang
 */
public abstract class BaseApi {

    protected ApiResult result(int code, Object data) {
        ApiResult res = new ApiResult();
        res.setCode(AppException.buildErrorCode(code));
        res.setData(data);
        return res;
    }

    protected ApiResult result(int code, String msg) {
        ApiResult res = new ApiResult();
        res.setCode(AppException.buildErrorCode(code));
        res.setMsg(msg);
        return res;
    }

    protected ApiResult result(int code, String msg, Object data) {
        ApiResult res = new ApiResult();
        res.setCode(AppException.buildErrorCode(code));
        res.setMsg(msg);
        res.setData(data);
        return res;
    }

    /*protected ApiResult result(int code, String msg, Object params, Object data) {
        ApiResult res = new ApiResult();
        res.setCode(AppException.buildErrorCode(code));
        res.setMsg(msg);
        res.setParams(params);
        res.setData(data);
        return res;
    }*/

    protected ApiResult result(int code, String msg, int data) {
        ApiResult res = new ApiResult();
        res.setCode(AppException.buildErrorCode(code));
        res.setMsg(msg);
        res.setData(AppException.buildErrorData(data));
        return res;
    }


    protected ApiResult success(Object data) {
        return result(RequestCode.success, "success", data);
    }

    protected ApiResult successNoData(Object data) {
        return result(RequestCode.success, "success");
    }

    protected ApiResult status(Object params) {
        return result(RequestCode.success, "success", params);
    }

   /* protected ApiResult success(Object params, Object data) {
        return result(RequestCode.success, "success", params, data);
    }*/

    protected ApiResult success() {
        return result(RequestCode.success, "success", "操作成功");
    }

    /*protected ApiResult success(String sid, String sign, Object data) {
        return result(RequestCode.success, sid, sign, data);
    }*/

    protected ApiResult stopConnect() {
        return result(RequestCode.forbid_error, "stopconnect", "");
    }

    protected ApiResult error(int error) {
        return result(error, "error");
    }

    protected ApiResult error(int error, String msg) {
        return result(error, msg);
    }

    protected ApiResult error(int error, String msg, int data) {
        return result(error, msg, data);
    }

    protected ApiResult error(int error, String msg, Integer data) {
        return result(error, msg, data);
    }

}
